
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.RequestDispatcher;

/**
 * Servlet implementation class AnmeldenServlet
 */
@WebServlet("/AnmeldenServlet")
public class AnmeldenServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       private BenutzerSpeicher meiner= BenutzerSpeicher.gibMirDeinenSpeicher();
       
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AnmeldenServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		
		RequestDispatcher index4= request.getRequestDispatcher("index4.jsp");
				index4.include(request, response);
	}
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		
		
		String e = request.getParameter("email");
		String p = request.getParameter("kennwort");
		Integer a = 0;
		
		
		request.setAttribute("keye", e);
		request.setAttribute("keyp", p);
		if (e != null&&p!=null){
			if (e.length()!=0&&p.length()!=0){
				if (meiner.stimmtDasPasswort(e, p)){
					a = 1;
					session.setAttribute("name", e);
					request.setAttribute("keya", a);
					RequestDispatcher index4= request.getRequestDispatcher("index4.jsp");
					index4.include(request, response);
					
				}
				else{
			request.setAttribute("keya", a);
			RequestDispatcher index4= request.getRequestDispatcher("index4.jsp");
			index4.include(request, response);
			}
			
		}
		else{
		RequestDispatcher index4= request.getRequestDispatcher("index4.jsp");
		index4.include(request, response);
		}
	}else{
		
		RequestDispatcher index4= request.getRequestDispatcher("index4.jsp");
		index4.include(request, response);

}
}}
